import React from 'react';
import { Link } from 'react-router';
import { connect } from 'react-redux'
import _ from 'lodash'

import { Table, Icon, Tag, Form,  Button, message, Modal, Input} from 'antd';
import { fetchOrderSpecial } from '../../store/actions';
import SearchInput from '../../components/search-input'
const _data_= [
    {
        id:'',
        subscribeDate: '12-05 12:00-15:00',
        patientName:'张三',
        gender:'M',
        age:'23',
        decs:'症状描述症状描述症状描述症状描述症状描述症状描述',
        history:'颈椎病',
        modality:'CT',
        part:'胸部'
    },{
        id:'',
        subscribeDate: '12-05 12:00-15:00',
        patientName:'李四',
        gender:'F',
        age:'56',
        decs:'症状描述症状描述症状描述症状描述症状描述症状描述',
        history:'无',
        modality:'CR',
        part:'足部'
    }
];

class _pane1 extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            user: this.props.user,
            data: this.props.data
        };
    }
    componentWillReceiveProps(nextProp){
        console.log('new',nextProp)
        this.setState({
            data: nextProp.data
        })
    }
    render(){
        const rowSelection = {
            /*onChange(selectedRowKeys, selectedRows) {
             console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
             },
             onSelect(record, selected, selectedRows) {
             console.log(record, selected, selectedRows);
             },
             onSelectAll(selected, selectedRows, changeRows) {
             console.log(selected, selectedRows, changeRows);
             }*/
        };

        /*
        * "id": "7570111e90304456b7b819d8dcfc55f8",
         "user_id": "869af4d0630344dfa6786d3f34bb5395",
         "specialist_id": "7095f2fd6a744722a16272293677f1e8",
         "product_id": "2",
         "study_id": "d220257cdf944748a76f4062b37a2d3b",
         "begintime": "2016-08-31T01:50:00.000Z",
         "endtime": "2016-08-31T02:00:00.000Z",
         "price": 10,
         "duration": 20,
         "urgent": 0,
         "memo": "tuwen",
         "status": 3,
         "create_time": "2016-08-30T09:44:53.000Z",
         "lastmodified": "2016-08-31T01:51:11.000Z",
         "productname": "图文交流/报告（10分钟）",
         "producttype": "G",
         "specialistname": "专家一",
         "patientname": "申坤",
         "check_item_name": "bbbbbb"
        * */

        const columns = [{
            title: '检查',
            dataIndex: 'check_item_name',
        }, {
            title: '患者姓名',
            dataIndex: 'patientname',
        }, {
            title: '创建时间',
            dataIndex: 'create_time'
        },{
            title: '服务类型',
            dataIndex: 'productname',
        }, {
            title: '价格(元)',
            dataIndex: 'price',
        },  {
            title: '状态',
            dataIndex: 'status',
            render(text){
                switch (text){
                    case 0:
                        return <span style={{color:'red'}}>未付款</span>;
                    case 1:
                        return <span style={{color:'#ff6600'}}>待处理</span>;
                    case 2:
                        return <span style={{color:'#333'}}>处理中</span>;
                    case 3:
                        return <span style={{color:'green'}}>交易完成</span>;
                    default:
                        return <span style={{color:'#ccc'}}>未知状态</span>;
                }
            }
        }, {
            title: '操作',
            render(record){
                return (<div>
                    <a href="#" data-id={`${record.id}`}>详情</a>
                </div>)
            }
        }];
        const pagination = {
            total: this.state.data.length,
            showSizeChanger: true,
            onShowSizeChange(current, pageSize) {
                /*console.log('Current: ', current, '; PageSize: ', pageSize);*/
            },
            onChange(current) {
                /*console.log('Current: ', current);*/
            }
        };
        console.log('this.props.data',this.state.data)
        return (
          <div>
              <Table
                pagination={pagination}
                columns={columns}
                rowSelection={rowSelection}
                dataSource={this.state.data}
              />
          </div>
        )
    }
}
class _SubscribeList extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            data:[]
        };
    }
    componentWillMount(){
        const _this =this;
        _this.props.dispatch(fetchOrderSpecial(null,{},function(res){
            console.log(res.content);
            _this.setState({
                data:res.content.list
            })
        }))
    }
    componentDidMount(){}
    render(){
        return (
          <div>
              <div style={{overflow: 'hidden', marginBottom: '10px', padding: '10px 0'}}>
                  <div style={{float:'left'}}>
                    <SearchInput style={{ width: 200 }} placeholder='请输入关键字查询' />
                  </div>
              </div>
              <_pane1 data={this.state.data} user={this.props.user} dispatch={this.props.dispatch} />
          </div>
        )
    }
}
let SubscribeList;
export default SubscribeList = connect((state)=>{
    const {user} = state.rootReducer;
    return {user}
})(_SubscribeList)

